home *** CD-ROM | disk | FTP | other *** search
- /* This program
- - prints the addresses of all the PSP's currently being used in memory and
- the handles opened in each of those processes.
- Handy if you have a lot of parent and child processes loaded.
- - was compiled using Lattice 3.00h
- - ASSUMES small memory model. I was too lazy to do a segread() to get the
- ds register. Instead, I took Lattice's value in _SS since ds == ss.
- - ASSUMES your environment area does not exceed 1000 bytes. If it does you
- need to change the array, environment, and the value in movedata().
- DOS has a theoretical maximum of 32K for its environment.
- - chgd for DOS 3.3, ps.environ is not null in command.com, instead after
- the double null is the name of the command processor i.e. COMMAND.COM
- */
-
- struct PROG_S_PRE { /* Program Segment Prefix */
- unsigned int interrpt; /* first two bytes are the instruction int 20h */
- /* this is a carryover from CP/M when you could */
- /* jump to the first byte of your program to exit */
- unsigned int machine; /* Memory size in paragraphs (16-bytes blocks) */
- char dos1;
- char call_dis[5]; /* FAR CALL to MS-DOS function dispatcher */
- unsigned long Int22; /* previous INT 22h, terminate process address IP,CS */
- unsigned long Int23; /* previous INT 23h, CNTRL-C exit address IP,CS */
- unsigned long Int24; /* previous INT 24h, Critical Error address IP,CS */
- unsigned int pre_psp; /* previous PSP segment */
- unsigned char hndl[20]; /* file handles - FF means the handle not assigned */
- unsigned int environ; /* segment address of the environment block */
- char dos2[4];
- unsigned int num_hdl; /* number of dos handles allocated */
- unsigned int hndl_off; /* offset of where the file handles are located */
- unsigned int hndl_seg; /* segment of where the file handles are located */
- char dos3[24];
- char dispatch[12]; /* code to call MS-DOS dispatcher INT 21 instructions */
- char fcb1[16]; /* unopened File Control Block #1 */
- char fcb2[16]; /* unopened File Control Block #2 */
- char dos4[4];
- char dta[128]; /* default Disk Transfer Area */
- } ps;
-
- struct EXTENDED_UNOPENED_FCB {
- char extd;
- char res[5];
- char attr;
- char drive;
- char file[8];
- char ext[3];
- unsigned int cur_blk;
- unsigned int rec_sz;
- unsigned long file_sz;
- unsigned int date;
- unsigned int time;
- char res2[8];
- unsigned char cur_rec;
- unsigned long rel_rec;
- } exfcb;
-
-
-
- extern int _psp[];
- extern int _env;
- extern int _esize;
- extern int _ss;
- char environment[1000];
- char command_com[] = "COMMAND.COM";
- char *double_null();
-
- void main()
- {
-
- unsigned int psp;
- char *p;
- int cmd_com=0;
- int first_time = 1;
-
-
- if( *(long *)(_env+_esize-2) != 0x00010000 )
- {
- cprintf("Your operating system does not have the name of your\n");
- cprintf("program at the end of the environment. You need DOS 3.1 or\n");
- cprintf("above. Or you are running Novell Advance Netware ver 1.02\n");
- cprintf("which clobbers the name area.\n");
- _exit(1);
- }
- psp = _psp[1]; /* get the segment word not the offset word */
-
- /* get current volume name and put in dta */
- exfcb.extd = 0xff; /* makes it an extended fcb */
- exfcb.attr = 0x08; /* asking for volume */
- exfcb.drive = 0; /* of current drive */
- strcpy( exfcb.file, "???????????"); /* both fields, file & ext */
- rstdta(); /* reset DTA to be pointing in the PSP */
- bdos( 0x11, &exfcb, 0 );
-
- do
- {
- /* move chucks of memory into our data segment area so that we can work with it */
- movedata( psp, 0, _ss, &ps, sizeof( struct PROG_S_PRE) );
- movedata( ps.environ, 0, _ss, &environment, 1000 );
-
- /* easy way to get progname for current program */
- if( first_time )
- {
- cprintf("I'm %s with machine memory of %dK\n",
- ( _env + _esize +2 ), ps.machine >> 6 );
- if( ps.dta[0] == '\377' )
- {
- ps.dta[19] = '\0';
- cprintf(" current volume name is %s\n", &ps.dta[8]);
- }
- cprintf("\n");
- first_time = 0;
- }
-
- if( ps.pre_psp == ps.hndl_seg ) cmd_com = 1; /* in COMMAND.COM */
- if( ps.environ == 0 ) /* not DOS 3.3 */
- p = command_com;
- else {
-
- /* find the name of the program following the environment space, Page 4-3 of
- MS-DOS manual, document # 8411-310-02, part # 036-014-012 */
- p = environment;
- while( *double_null( &p ));
-
- if( cmd_com ) p++; else p += 3;
- }
- cprintf("psp at %dK for %s", psp>>6, p );
- cprintf(" maximum number of handles is %d\n",ps.num_hdl);
- if( ps.hndl_off == 0x18 && ps.hndl_seg == psp )
- {
- /* display which handles are active for each program */
- /* the field psp is being used as a work int - not good form but ...*/
- for( psp = 0; psp < 20; psp++)
- {
- if( ps.hndl[psp] != 0xff )
- cprintf(" %d",psp);
- }
- cprintf("\n");
- psp = ps.pre_psp;
- } else {
- cprintf("handles not in psp ");
- }
- } while( ! cmd_com );
- }
- char *double_null( p )
- char **p;
- {
- while( *(*p)++ );
- return( *p );
- }